package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.BookingDTO;
import model.UserDTO;
import model.search.BookingSearchDTO;
import util.UrlUtility;
import bizlogic.BookingManager;

@WebServlet("/ApproveReject")
public class ApproveRejectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ApproveRejectServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doShow(request, response);
	}

	private void doShow(HttpServletRequest req, HttpServletResponse res) {
		// Show the Pending Booking
		BookingManager bm = new BookingManager();
		ArrayList<BookingDTO> list = new ArrayList<BookingDTO>();
		UserDTO user = (UserDTO)req.getSession().getAttribute("user");
		
		// Define the Status filter
		ArrayList<String> status = new ArrayList<String>();
		status.add("Book");
		status.add("Update");
		
		// Define the Search Filter
		BookingSearchDTO bs = new BookingSearchDTO();
		bs.setStatus(status);
		bs.setManagerId(user.getId());
		
		System.out.println(bs);
		
		// Get the booking list
		list = bm.findBookingByCriteria(bs);
		
		// Redirect to page
		String address = "/WEB-INF/ShowToEvaluate.jsp";
		
		// Attach the objects to Request object
		req.setAttribute("bookinglist", list);
		
		System.out.println("Size: " + list.size());
		UrlUtility.forwardPage(req, res, address);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	
	
}
